from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from goods.models import SpecificationOption, SPUSpecification
from meiduo_admin.serializers.options import OptionSerializer, SpecificationSerializer
from meiduo_admin.utils import PageNum


class OptionsView(ModelViewSet):
    # 指定查询集
    queryset = SpecificationOption.objects.all()
    # 指定序列化器
    serializer_class = OptionSerializer
    # 指定分页器
    pagination_class = PageNum
    # 指定管理员权限
    permission_classes = [IsAdminUser]

    def simple(self, request):
        specifications = SPUSpecification.objects.all()
        ser = SpecificationSerializer(specifications, many=True)
        return Response(ser.data)

